<?php
	/**
	 * Static validator
	 * @author IMP
	 */
	
	class StaticUserLoginValidator implements UserLoginValidator {
		private $data = array(), $callback = 'md5';
		
		public function __construct(array $data, $cb = 'md5'){
			$this->data = $data;
			
			if(!is_callable($cb)){
				throw new Exception('Invalid callback given.');
			}else{
				$this->callback = $cb;
			}
		}
		
		public function validate($username, $password){
			if(array_key_exists($username, $this->data)){
				if($this->data[$username] == call_user_func($this->callback, $password)){
					return new User($username);
				}else{
					return null;
				}
			}else{
				return null;
			}
		}
	}
?>